<?php $this->load->view('common/header');?>
<?php echo admin_js_url('select2/select2.full.min');?>
<?php echo admin_css_url('select2');?>
<?php echo admin_js_url('area');?>
<body class="padding_top">
<!-- head [[-->
<div class="head_box">
	<div class="bank_nav">
        <a href="<?php echo site_url('member');?>"><i class="ico"></i></a>
    </div>
    <div class="head_title">下单</div>
</div>
<!--]] head -->
<!-- info [[-->
<div class="certified_form">
    <div class="default_box">
        <dl>
            <dt>产品类型</dt>
            <dd>
                <span class="select">
                    <i class="ico"></i>
                    <select name="category_id[]" class="category_id">
                        <option value="0">请选择产品类型</option>
                        <?php if(isset($cates)){?>
                            <?php foreach ($cates as $k => $v) {?>
                            <option value="<?php echo $v['id'] ?>"><?php echo $v['category_name'] ?></option>
                            <?php  }?>
                        <?php }?>
                    </select>
                </span>
            </dd>
        </dl>
        <dl>
            <dt>产品名称</dt>
            <dd>
                <span class="select">
                    <i class="ico"></i>
                    <select name="product_id[]" class="product_id">
                        <option value="0">请选择产品名称</option>

                    </select>
                </span>
            </dd>
        </dl>
        <dl class="good_guige_box">
            <dt>规格</dt>
            <dd class="good_guige_dd">
                <span class="content good_guige"></span>
            </dd>
        </dl>
        <dl class="good_gongyi_box">
            <dt>制作工艺</dt>
            <dd class="good_gongyi_dd">
                <span class="content good_gongyi"></span>
            </dd>
        </dl>
        <dl class="good_part_number_box">
            <dt>料号</dt>
            <dd class="good_part_number_dd">
                <span class="content good_part_number"></span>
            </dd>
        </dl>
        <dl class="good_price_box">
            <dt>单价</dt>
            <dd class="good_price_dd">
                <span class="content good_price"></span>
            </dd>
        </dl>
        <dl class="good_num_box">
            <dt>下单数量</dt>
            <dd class="good_num_dd">
                <em class="money">金额：￥<b class="total_price">0.00</b></em>
                <span class="input">
                    <input price="" placeholder="请输入下单数量" class="good_mum" name="good_mum[]">
                </span>
            </dd>
        </dl>
        <dl>
            <dt>&nbsp;</dt>
            <dd>
                <a href="javascript:;" class="add del_clone_box">删除</a>
            </dd>
        </dl>
        <dl class="sure_nav">
            <a href="javascript:;" id="add_clone_box">继续添加</a>
            <a href="javascript:;" id="order_do">下一步</a>
        </dl>
    </div>
</div>
<div id="clone_box" style="display: none">
    <div class="default_box">
        <dl>
            <dt>产品类型</dt>
            <dd>
                <span class="select">
                    <i class="ico"></i>
                    <select name="category_id[]" class="category_id">
                        <option value="0">请选择产品类型</option>
                        <?php if(isset($cates)){?>
                            <?php foreach ($cates as $k => $v) {?>
                                <option value="<?php echo $v['id'] ?>"><?php echo $v['category_name'] ?></option>
                            <?php  }?>
                        <?php }?>
                    </select>
                </span>
            </dd>
        </dl>
        <dl>
            <dt>产品名称</dt>
            <dd>
                <span class="select">
                    <i class="ico"></i>
                    <select name="product_id[]" class="product_id">
                        <option value="0">请选择产品名称</option>

                    </select>
                </span>
            </dd>
        </dl>
        <dl class="good_guige_box">
            <dt>规格</dt>
            <dd class="good_guige_dd">
                <span class="content good_guige"></span>
            </dd>
        </dl>
        <dl class="good_gongyi_box">
            <dt>制作工艺</dt>
            <dd class="good_gongyi_dd">
                <span class="content good_gongyi"></span>
            </dd>
        </dl>
        <dl class="good_part_number_box">
            <dt>料号</dt>
            <dd class="good_part_number_dd">
                <span class="content good_part_number"></span>
            </dd>
        </dl>
        <dl class="good_price_box">
            <dt>单价</dt>
            <dd class="good_price_dd">
                <span class="content good_price"></span>
            </dd>
        </dl>
        <dl class="good_num_box">
            <dt>下单数量</dt>
            <dd class="good_num_dd">
                <em class="money">金额：￥<b class="total_price">0.00</b></em>
                <span class="input">
                    <input price="" placeholder="请输入下单数量" class="good_mum" name="good_mum[]">
                </span>
            </dd>
        </dl>
        <dl>
            <dt>&nbsp;</dt>
            <dd>
                <a href="javascript:;" class="add del_clone_box">删除</a>
            </dd>
        </dl>
    </div>
</div>
<script>
    $(function () {
        $("#add_clone_box").click(function () {
            var addItem = $("#clone_box").children().clone(true).show();
            $('.sure_nav').before(addItem);
        });
        $(".del_clone_box").click(function () {
            $(this).parent().parent().parent().fadeOut();
        });
    });
    // 提交
    $(document).on('touchend','#order_do',function(){
        var good_mum =[];
        $("input[name='good_mum[]']").each(function(){
            if($(this).val() != ''){
                good_mum.push($(this).val());
            }

        });
        var category_id =[];
        // $("select[name='category_id[]'").each(function(){
        $(".category_id").each(function(){
            if($(this).val()> 0){
                category_id.push($(this).val());
            }
        });
        var product_id =[];
        // $("select[name='product_id[]'").each(function(){
        $(".product_id").each(function(){
            if($(this).val()> 0){
                product_id.push($(this).val());
            }
        });
        var URL= baseurl+"index.php/order/create_order";
        $.ajax({
            type: "post",
            url: URL,
            dataType:'json',
            data: {
                'good_mum':good_mum,
                'product_id':product_id,
                'category_id':category_id,
                'csrf_test_name': ci_csrf_token()
            },
            success: function(data){
                if(data.status == 200){
                    window.location.href = data.url;
                }else{
                    layer.msg(data.msg);
                    return false;
                }

            }
        });
    });

    $(".kaipiao").click(function () {
        $(this).addClass("on");
        $(this).siblings().removeClass("on");
    });
    $(".songhuo").click(function () {
        $(this).addClass("on");
        $(this).siblings().removeClass("on");
    });
    function isInteger(obj) {
        return typeof obj === 'number' && obj%1 === 0
    }
</script>
<!--]] info -->
</body>
</html>
